//
//  LYNavigationController.m
//  artist
//
//  Created by Jay_Apple on 16/2/29.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYNavigationController.h"
#import "UIImage+Image.h"
@interface LYNavigationController ()

@end

@implementation LYNavigationController

+ (void)initialize{

    UINavigationBar *appearance = [UINavigationBar appearance];
    
    [appearance setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:LYNavBGColor alpha:1.0]] forBarMetrics:UIBarMetricsDefault];
    [appearance setShadowImage:[UIImage imageNamed:@"头部分割线"]];

}

/**
 * 可以在这个方法中拦截所有push进来的控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        [button setImage:[UIImage imageNamed:@"返回按钮"] forState:UIControlStateNormal];
////        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
//        button.My_Size = CGSizeMake(70, 30);
//        // 让按钮内部的所有内容左对齐
//        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        //        [button sizeToFit];
//        // 让按钮的内容往左边偏移10
//        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
//        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        
        // 修改导航栏左边的item
//        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回按钮"] style:UIBarButtonItemStyleDone target:self action:@selector(pop)];
        // 隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
    
}

- (void)pop
{
    [self popViewControllerAnimated:YES];
}

@end
